package com.oscar.ehome.view.teamview.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.bean.teamBean.UserRoleStaticBean;
import com.oscar.ehome.bean.teamBean.UserStartStaticBean;
import com.oscar.ehome.utils.system.SystemConfigFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/31.
 */

public class StarssGvAdapter extends BaseAdapter {
    private List<UserRoleStaticBean.ListBean> list = new ArrayList<>();
    List<Integer> list_color = new ArrayList<>();
    private List<UserStartStaticBean.StartsListBean> startslist = new ArrayList<>();
    int p = 0;
    int size = 0;
    Context con;

    public StarssGvAdapter(Context con, List<UserRoleStaticBean.ListBean> jobList, List<Integer> list_color) {
        this.list = jobList;
        this.list_color = list_color;
        this.con = con;
    }

    public StarssGvAdapter(Context con, List<UserStartStaticBean.StartsListBean> startslist, int p, List<Integer> list_color) {
        this.startslist = startslist;
        this.list_color = list_color;
        this.con = con;
        this.p = p;
    }

    @Override
    public int getCount() {
        if (p == 0) {//职级统计时
            if (list == null) {
                return 0;
            } else {
                size = list.size();
            }
        } else {//星级统计
            if (startslist == null) {
                return 0;
            } else {
                size = startslist.size();
            }
        }
        return size;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if (convertView == null) {
            vh = new ViewHolder();
            convertView = View.inflate(parent.getContext(), R.layout.starss_item_gv, null);
            vh.item_leven = (TextView) convertView.findViewById(R.id.tv_starss_leven);
            vh.hunnum = (TextView) convertView.findViewById(R.id.tv_starss_humnum);
            vh.yanse = (ImageView) convertView.findViewById(R.id.yanse);

            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();

        }
        switch (p) {
            case 0://职级统计
                UserRoleStaticBean.ListBean jobListBean = list.get(position);
                if (jobListBean != null) {
                    if (jobListBean.getRoleMobile() != null) {
                        vh.item_leven.setText(jobListBean.getRoleMobile().getRoleName());
                    }
                    int countNum = jobListBean.getRoleMobileUserNum();
                    vh.hunnum.setText(countNum + "人");
                    vh.hunnum.setTextColor(Color.parseColor(SystemConfigFactory.getInstance(con).getSystemConfig().getColor()));
                    vh.yanse.setImageResource(list_color.get(position));
                }
                break;
            case 1://星级统计
                UserStartStaticBean.StartsListBean ListBean = startslist.get(position);
                if (ListBean != null) {
                    int leves = ListBean.getStarLevel();
                    if (leves == 0) {
                        vh.item_leven.setText("零星");
                    } else if (leves == 1) {
                        vh.item_leven.setText("一星");
                    } else if (leves == 2) {
                        vh.item_leven.setText("二星");
                    } else if (leves == 3) {
                        vh.item_leven.setText("三星");
                    }
                    int countNum = ListBean.getRoleMobileUserNum();
                    vh.hunnum.setText(countNum + "人");
                    vh.hunnum.setTextColor(Color.parseColor(SystemConfigFactory.getInstance(con).getSystemConfig().getColor()));
                    vh.yanse.setImageResource(list_color.get(position));
                }
                break;
        }

        return convertView;
    }

    static class ViewHolder {
        TextView item_leven;
        TextView hunnum;
        ImageView yanse;
    }
}
